
package com.probiz.estoresa.customer.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.customer.Address;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.customer.service.AddressManager;

public class AddressController extends GenericStoreAdminController<Address> {
	
	private AddressManager		addressManager	= null;
	private static final String	Address_LIST	= "addressList";

	public void setAddressManager(AddressManager manager) {
		addressManager = manager;
	}
	
	@Override
	protected void initController() throws Exception {
		this.mgr = addressManager;
	}

	@Override
	protected String getEntityName(Address entity) {
		return entity.getAddress();
	}


	@Override
	protected void preSave(HttpServletRequest request, Address entity, BindException errors) {
	}

	public ModelAndView defaultAction(HttpServletRequest request, HttpServletResponse response){
		if (logger.isDebugEnabled()) {
			logger.debug("entering 'AddressController defaultAction' method...");
		}

		// return a paging list
		List results = getPagingList(request, response);
		return new ModelAndView("customer/addressList", Address_LIST, results);
	}

	/**
	 * query a paging list
	 * 
	 * @param request
	 * @param response
	 * @return List I18ntextItem's list
	 */
	private List getPagingList(HttpServletRequest request, HttpServletResponse response) {

		List results = null;

//		String customerId = request.getParameter("appuserId");
//
//		if (customerId != null) {// if customerid has exsit
//			results = mgr
//					.getAllByAppuserId(new Integer(customerId), pagingBean);
//		} else {// or get all address and paging
//			results = mgr.getAddresssAllDesc(pagingBean);
//		}
//
//		if (logger.isDebugEnabled()) {
//			logger.debug("results found:" + results.size() + " totalItems:"
//					+ pagingBean.getNumberOfItems());
//		}

		return results;
	}

}
